﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data;
using MySql.Data.MySqlClient;
using System.Data;
using System.Data.Odbc;


namespace ComputerStoreManager
{
    public partial class Connection
    {

        private static Connection _instance;
        private static object syncLock = new object();

        public static Connection GetInstance() {
            if (_instance == null) {
                lock (syncLock) {
                    if (_instance == null) {
                        _instance = new Connection();
                    }
                }
            }
            return _instance;
        }

        #region Variables
        private MySqlConnection m_connection;
        private string m_error;
        #endregion

        #region Properties
        public string Error
        {
            get { return m_error; }
            set { m_error = value; }
        }
        #endregion

        public Connection() 
        {
            //string strConnection = "SERVER=localhost;" + "Port=3306;" + "DATABASE=quanlylinhkien;" + "UID=root;" + "PASSWORD=8979343 ;";
            string strConnection = "SERVER=112.213.84.73;" + "Port=3306;" + "DATABASE=quanlylinhkien;" + "UID=root;" + "PASSWORD=btb***nohack;";
            //string strConnection = "SERVER=localhost;" + "Port=3306;" + "DATABASE=quanlylinhkien;" + "UID=root;" + "PASSWORD= angellove&&641;";
            m_connection = new MySqlConnection(strConnection);
        }

        public bool Connect()
        {
            try {
                m_connection.Open();
            }
            catch (Exception ex) {
                Error = "Loi khi open ket noi" + ex.Message;
                return false;
            }
            return true;
        }
        public void Disconnect()
        {
            if(m_connection.State == ConnectionState.Open) {
                m_connection.Close();
            }
        }

    }
}
